<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>控制台 - 教学管理系统首页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <#include "../../head/common-css.ftl" />
    <#include "../../head/common-js.ftl" />
    <script>
        var permission_options;
        // 加载菜单信息
        $(function () {
            permission_options = {
                url: 'doList.do',
                page: true,
                params: {},
                index: true,
                cont: 'permission_page',
                pageSize: 20,
                column: [{
                    name: 'permissionName',
                    title: '权限名称',
                    width: 70,
                    align: 'center'
                }, {
                    name: 'permissionCode',
                    title: '权限  编码',
                    width: 70,
                    align: 'center'
                }, {
                    name: 'createTime',
                    title: '创建时间',
                    width: 130,
                    align: 'center',
                    render: function (value) {
                        if (value) {
                            return formatTime(value.time)
                        }
                        return '无时间'
                    }
                }, {
                    name: 'status',
                    title: '状态',
                    width: 40,
                    align: 'center',
                    render: function (value) {
                        if (value == '1') {
                            return '有效';
                        }
                        return '无效';
                    }
                }, {
                    name: 'id',
                    title: '操作',
                    width: 60,
                    align: 'center',
                    render: function (value, data) {
                        var operate = '<div class="btn-group">';
                        // 修改按钮
                        operate += '<button class="btn btn-xs btn-info" onclick=operate("' + value + '")> <i class="icon-edit bigger-120"></i> </button>';
                        if (data.status == 1) {
                            // 删除按钮
                            operate += '<button class="btn btn-xs btn-danger" onclick=validStatus("' + value + '",2)> <i class="icon-trash bigger-120"></i> </button>';
                        } else {
                            // 删除按钮
                            operate += '<button class="btn btn-xs btn-success" onclick=validStatus("' + value + '",1)> <i class="icon-ok bigger-120"></i> </button>';
                        }
                        operate += '</div>';
                        return operate;
                    }
                }]
            };
            var list = $('#permission_list').table(permission_options);
            window.setTimeout(function () {
                reinitTreeHight(window.parent.getIframeByElement(document.body));
            }, 200)
        });

        //列点击事件
        $(function () {
            // // 点击搜索按钮
            $('#searchBtn').click(function () {
                permission_options.params.permissionName = $('#permission_name').val();
                $('#permission_list').table(permission_options);
            });
            // 点击添加按钮
            $('#addBtn').click(function () {
                $("#permissionAddModal").modal({
                    backdrop: 'static',  	// 点击空白不关闭
                    keyboard: false,		// 按键盘esc也不会关闭
                    remote: '${request.contextPath}/sys/permission/operate.htm'	// 从远程加载内容的地址
                });
            });
            // dialog展示事件
            $('#permissionAddModal').on('shown.bs.modal', function () {//捕获show事件
                reinitTreeHight(window.parent.getIframeByElement(document.body), '.page-content');
            });

            $("#permissionAddModal").on("hidden.bs.modal", function () {
                $(this).removeData("bs.modal");
                reinitTreeHight(window.parent.getIframeByElement(document.body));
            });
        });

        // 修改操作
        function operate(id) {
            $("#permissionAddModal").modal({
                backdrop: 'static',  	// 点击空白不关闭
                keyboard: false,		// 按键盘esc也不会关闭
                remote: '${request.contextPath}/sys/permission/operate.htm?id=' + id	// 从远程加载内容的地址
            });
        }

        // 删除操作
        function validStatus(id, status) {
            layer.confirm(status == 2 ? '是否确认要删除权限<span style="color: red">(菜单需要重新设置)</span>？' : '是否确认要恢复权限？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                $.ajax({
                    url: "validStatus.do",
                    type: "post",
                    data: {
                        'id': id,
                        'status': status
                    },
                    dataType: "json",
                    success: function (result) {
                        // 判断是否成功
                        if (result.success) {
                            layer.msg(status == 2 ? '删除成功' : '恢复成功', {icon: 2}, function () {
                                $(parent.document).find("iframe").each(function () {
                                    if ($(this).attr('src').indexOf("permission/list.htm") > -1) {
                                        $(this).attr('src', $(this).attr('src'));
                                        reinitTreeHight(this);
                                    }
                                });
                            });
                        } else {
                            layer.msg(result.msg, {icon: 5});
                        }
                    }
                });
            });
        }
    </script>
</head>
<body>
<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="widget-box">
                <div class="widget-header">
                    <h5 class="smaller">权限信息</h5>
                </div>

                <div class="widget-body">
                    <div class="widget-main padding-6">
                        <div class="table-responsive page-content">
                            <form class="form-inline">
                                <label for="permission_name">权限名:</label>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" class="input-medium" id="permission_name">
                                    </div>
                                </div>
                                <button type="button" id="searchBtn" class="btn btn-info btn-xs">
                                    <i class="icon-eye-open"></i>
                                    查询
                                </button>
                                <button type="button" id="addBtn" class="btn btn-info btn-xs">
                                    <i class=" icon-book"></i>
                                    添加权限
                                </button>
                            </form>
                            <div class="space-4"></div>
                            <!-- table start -->
                            <table class="table-list table-hover" id="permission_list"></table>
                            <div class="pager" id="permission_page"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 弹出模态窗口-->
<div class="modal fade" tabindex="-1" role="dialog" id="permissionAddModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>